//
//  QLMeetPeopleVC.m
//  神约
//
//  Created by qlwl on 17/1/23.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLMeetPeopleVC.h"
#import "UIView+FrameKIt.h"
#import "QLPeopleNearbyVC.h"
#import "QLLiveVideoListVC.h"
#import "QLCircleOfFriendsVC.h"

@interface QLMeetPeopleVC ()
@property (weak, nonatomic) IBOutlet UIButton *topBtn1;
@property (weak, nonatomic) IBOutlet UIButton *topBtn2;
@property (weak, nonatomic) IBOutlet UIButton *topBtn3;
@property (weak, nonatomic) IBOutlet UIButton *switchBtn;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIView *subBgView1;
@property (weak, nonatomic) IBOutlet UIView *subBgView2;
@property (weak, nonatomic) IBOutlet UIView *subBgView3;

@property (nonatomic, assign) BOOL switchToBig ; //


@property (weak, nonatomic) UIView *lineView;

@property (nonatomic, weak) QLPeopleNearbyVC * nearbyVC ;
@property (nonatomic, weak) QLLiveVideoListVC * videoVC ;
@property (nonatomic, weak) QLCircleOfFriendsVC * dynamicVC ;

@end

@implementation QLMeetPeopleVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavBarColor:NavBarTintColor];
    self.topBtn1.superview.f_width = iphoneWidth;
    
    UIView * view = [[UIView alloc] init];
    view.backgroundColor = [UIColor colorWithRed:0.99f green:0.98f blue:0.18f alpha:1.00f];
    [self.topBtn1.superview addSubview:view];
    self.lineView = view ;
    self.lineView.f_width = self.topBtn1.f_width + 10;
    self.lineView.f_bottom = self.topBtn1.superview.f_height -1;
    self.lineView.f_height = 1;
    self.lineView.f_left = self.topBtn1.f_left - 5;
    self.switchBtn.hidden = !self.topBtn1.selected;
    
    
    [self addSubControllers];
}

- (void)addSubControllers
{
    QLPeopleNearbyVC * nearVC = [NSString instantiateViewControllerWithIdentifier:@"QLPeopleNearbyVC" andSBName:@"Dynamic"];
    [self addChildViewController:nearVC];
    nearVC.view.frame = self.subBgView1.bounds;
    [self.subBgView1 addSubview:nearVC.view];
    self.nearbyVC = nearVC;
    
    QLLiveVideoListVC * videoListVC = [NSString instantiateViewControllerWithIdentifier:@"QLLiveVideoListVC" andSBName:@"Dynamic"];
    [self addChildViewController:videoListVC];
    videoListVC.view.frame = self.subBgView3.bounds;
    [self.subBgView3 addSubview:videoListVC.view];
    self.videoVC = videoListVC;
    
    QLCircleOfFriendsVC * dynamicVC = [NSString instantiateViewControllerWithIdentifier:@"QLCircleOfFriendsVC" andSBName:@"Discover"];
    [self addChildViewController:dynamicVC];
    dynamicVC.view.frame = self.subBgView2.bounds;
    [self.subBgView2 addSubview:dynamicVC.view];
    self.dynamicVC = dynamicVC;
}

- (IBAction)topBtn1Click:(id)sender {
    [self selectBtns:sender];
    [self scrollToPage:0];
}
- (IBAction)topBtn2Click:(id)sender {
    [self selectBtns:sender];
    [self scrollToPage:1];
}
- (IBAction)topBtn3Click:(id)sender {
    [self selectBtns:sender];
    [self scrollToPage:2];
}

- (IBAction)switchBigImaClick:(id)sender {
    UIButton * btn = sender;
    self.switchToBig = !self.switchToBig;
    [btn setTitle:self.switchToBig?@"切换大图":@"切换小图" forState:UIControlStateNormal];
    [self.nearbyVC reloadIma];
}
- (IBAction)screenBtnClick:(id)sender {
    
}

- (void)selectBtns:(UIButton *)btn
{
    NSArray * allBtns = @[self.topBtn1,self.topBtn2,self.topBtn3];
    for (UIButton * btn in allBtns) {
        btn.selected = NO;
        btn.userInteractionEnabled = YES;
    }
    btn.selected = YES;
    btn.userInteractionEnabled = NO;
    [self scrollToBtn:btn];
    self.switchBtn.hidden = !self.topBtn1.selected;
}
- (void)scrollToBtn:(UIButton *)btn
{
    [UIView animateWithDuration:0.2 animations:^{
        self.lineView.f_width = btn.f_width + 10;
        self.lineView.f_left = btn.f_left - 5;
    }];
}

- (void)scrollToPage:(int)page
{
    [self.scrollView setContentOffset:CGPointMake(self.scrollView.bounds.size.width * page, 0) animated:YES];
}



@end
